import request from './request'

// 获取菜单列表
export const getMenuList = (params) => {
  return request({
    url: '/menus',
    method: 'get',
    params
  })
}

// 获取菜单树形结构
export const getMenuTree = (params) => {
  return request({
    url: '/menus/tree',
    method: 'get',
    params
  })
}

// 获取单个菜单信息
export const getMenuInfo = (id) => {
  return request({
    url: `/menus/${id}`,
    method: 'get'
  })
}

// 创建菜单
export const createMenu = (data) => {
  return request({
    url: '/menus',
    method: 'post',
    data
  })
}

// 更新菜单信息
export const updateMenu = (id, data) => {
  return request({
    url: `/menus/${id}`,
    method: 'put',
    data
  })
}

// 删除菜单
export const deleteMenu = (id) => {
  return request({
    url: `/menus/${id}`,
    method: 'delete'
  })
}

// 更新菜单状态
export const updateMenuStatus = (id, status) => {
  return request({
    url: '/menus/status',
    method: 'post',
    data: { id, status }
  })
}

// 更新菜单显示状态
export const updateMenuVisible = (id, visible) => {
  return request({
    url: '/menus/visible',
    method: 'post',
    data: { id, visible }
  })
}

// 根据角色编码获取菜单列表
export const getMenusByRoleCode = (roleCode) => {
  return request({
    url: `/menus/role/${roleCode}`,
    method: 'get'
  })
}

// 根据角色编码获取菜单树形结构
export const getMenuTreeByRoleCode = (roleCode) => {
  return request({
    url: `/menus/tree/role/${roleCode}`,
    method: 'get'
  })
}

// 为角色分配菜单
export const assignMenusToRole = (roleCode, data) => {
  return request({
    url: `/menus/assign`,
    method: 'post',
    data: { ...data, roleCode }
  })
}

// 获取用户菜单列表
export const getUserMenus = (userId) => {
  return request({
    url: `/menus/user/${userId}`,
    method: 'get'
  })
}

// 获取用户菜单树形结构
export const getUserMenuTree = (userId) => {
  return request({
    url: `/menus/tree/user/${userId}`,
    method: 'get'
  })
}